package vnc.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;

import javax.swing.JPanel;

import vnc.ui.PacketBox;

import jpcap.packet.Packet;

public class MovingBox extends JPanel{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	static BoxContainer bc;
	static PacketDetails pd;
	
	static int currentItem;
	static int beforeCurrentItem;
	static int wishItem;
	
	static Point startP;
	static Point currentP;
	
	static Dimension currentD;
	static Dimension restD;
	static Dimension spaceD;

	static List<PacketBox> boxes;
	
	public static void removeBoxBorder(PacketBox box){
		box.setBorderPainted(false);
		box.setContentAreaFilled(false);
		box.setDefaultCapable(false);
		box.setFocusPainted(false);
	}
	
	public void clear(){
		bc.clear();
		//pd.removeAll();
	}
	
	public void removeBox(int index){
		bc.removeBox(index);
	}
	
	public void init(){
		currentItem = 0;
		beforeCurrentItem = 0;
		wishItem = 0;
	}
	
	public MovingBox(List<Packet> packets, int width, int height) {
		
		init();
		
		currentD = new Dimension(114, 114);
		restD = new Dimension(85, 85);
		spaceD = new Dimension((width/2)-(currentD.width/2), 2);
		
		boxes = new ArrayList<PacketBox>();
		
		// location for boxes not for this panel
		startP = new Point(spaceD.width, spaceD.height + (currentD.height - restD.height));
		currentP = new Point(width/2 - currentD.width/2, spaceD.height);
		
		this.setBackground(Color.white);
		
		this.setLayout(null);
		
		pd = new PacketDetails();
		bc = new BoxContainer(packets ,boxes, this);
		
		this.add(pd);
		this.add(bc);
		
		pd.setBounds(-1, 0, 1024, 370);
		// because of the border eating 1 pixel,, that's why put -1
		bc.setBounds(-1, 370, 1024, 150);
		
		bc.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
		
		bc.t.start();
		
	}

}